<template >
  <div class="select_conpont_type-container">
    <breadcrumb style="position: absolute;width:100%;"></breadcrumb>
    <div class="content">
      <div class="query">
        <div class="margin_right_20">
          商品标签名称:&nbsp;
          <el-input
            v-model="goodsTypeName"
            placeholder="请输入内容"
            style="width:100px;height:30px;"
            @keyup.enter.native="get_list(1)"
          ></el-input>
        </div>
        <div class="margin_right_20">
          商品类型:&nbsp;
          <el-select v-model="goodsTypeId" style="width: 100px;">
            <el-option label="全部" value></el-option>
            <el-option
              v-for="(item, index) in goodsTypes"
              :key="index"
              :label="item.name"
              :value="item.id"
            ></el-option>
          </el-select>
        </div>

        <div class="btn">
          <el-button type="primary" icon="el-icon-search" @click="get_label_list(1)">查询</el-button>
        </div>
      </div>
      <div class="table">
        <el-table
          :data="labelList"
          style="width: 100%"
          height="528"
          @selection-change="handleSelectionChange"
        >
          <el-table-column type="selection" width="55"></el-table-column>
          <el-table-column prop="goodsTypeName" label="商品类型名称"></el-table-column>
          <el-table-column prop="goodsLabelName" label="商品标签名称"></el-table-column>
          <el-table-column prop="createTime" label="创建时间"></el-table-column>
        </el-table>
        <pagination
          :currentPage="currentPage"
          :page="page"
          :total="total"
          :pageSize="pageSize"
          @change-current="currentChange"
          @change-size="sizeChange"
        ></pagination>

        <div class="btn">
          <el-button type="primary" @click="addLabel">确 定</el-button>
          <el-button style="color: #409eff" @click="$router.go(-1)">取 消</el-button>
        </div>
      </div>
    </div>
  </div>
</template>
<script>
import breadcrumb from "../../components/breadcrumb";
import pagination from "../../components/page";
import { label_list, goodsType } from "../../api/getData.js";
export default {
  components: { breadcrumb, pagination },
  data() {
    return {
      currentPage: 1,
      labelList: [],
      total: 0,
      page: 1,
      pageSize: 10,
      goodsTypeName: "",
      goodsTypeId: "",
      goodsTypes: []
    };
  },
  created() {
    this.get_label_list();
    this.getGoodsType();
  },
  methods: {
    sizeChange(val) {
      this.pageSize = val;
      this.currentPage = 1;
      this.get_label_list();
    },
    currentChange(val) {
      this.currentPage = val;
      this.get_label_list();
    },

    handleSelectionChange(val) {
      this.val = val;
    },
    get_label_list(currentPage) {
      this.labelList = [];
      if (currentPage) {
        this.currentPage = currentPage;
      }
      var data = {
        current: this.currentPage,
        size: this.pageSize,
        name: this.goodsTypeName,
        typeId: this.goodsTypeId
      };
      label_list(data).then(res => {
        if (res.data.status == 0 && res.data.data.records.length != 0) {
          this.labelList = res.data.data.records;
          this.total = res.data.data.total;
          this.page = Math.ceil(this.total / this.pageSize);
        }
      });
    },
    getGoodsType() {
      goodsType().then(res => {
        if (res.data.status == 0 && res.data.data.length != 0) {
          this.goodsTypes = res.data.data;
        }
      });
    },
    addLabel() {
      if (this.val.length == 0) {
        return this.$message({
          type: "warning",
          message: "请选择商品标签"
        });
      }
      localStorage.setItem("selectLabels", JSON.stringify(this.val));
      this.$router.go(-1);
    }
  }
};
</script>

<style lang="less" >
.select_conpont_type-container {
  @import "../../style/table.less";
  @import "../../style/content.less";
  display: flex;
  flex-flow: column;
  position: relative;
  height: 100%;
  .el-table .cell {
    white-space: pre-line !important;
  }
  .content {
    .query {
      .start_time {
        display: flex;
        align-items: center;
      }
      .end_time {
        display: flex;
        align-items: center;
      }
      .btn {
        .el-button {
          width: 70px;
        }
      }
    }
  }
  .table > .btn {
    margin-top: 70px;
    text-align: center;
    > button {
      height: 30px !important;
      line-height: 30px;
      padding: 0;
      width: 60px;
      margin: 0 70px;
      // box-sizing: content-box;
    }
  }
}
</style>

